package com.snapp.web.actions;

import java.util.Vector;

import javax.servlet.http.HttpServletRequest;

import org.jdom.Element;

import com.snapp.util.object.model.ObjectModel;
import com.snapp.util.object.model.ObjectImpl;
import com.snapp.web.SNAppAction;
import com.snapp.web.agents.SNAppAgent;

public class List extends SNAppAction {
	public Vector<ObjectModel> list = null;
	
	public String execute(HttpServletRequest req) {
		setSNAppGlobalId(req.getParameter("SNAppGlobalId"));
		if (getSNAppGlobalId() == null) {
			setResultCode(-1);
			setResultMessage("Missing \"SNAppGlobalId\" parameter.  Not sure which object to load.");
			return super.execute(req);
		}
		try {
			SNAppAgent agent = new SNAppAgent();
			list = agent.list(getSNAppGlobalId(), consolidateReadMap(req));
			
			setResultCode(RESULT_CODE_SUCCESS);
			setResultMessage("Object list loaded successfully.");

			Element list_xml = ObjectImpl.listToXML(list); 
			setBodyElement(list_xml);
		
		} catch(Exception e) {
			setResults(RESULT_CODE_WARNING, "Error parsing dbo bean to xml.");
			log("Error parsing dbo bean to xml.",e);
		}
		
		return super.execute(req);
	}

	public Vector<ObjectModel> getList() {
		return list;
	}
	
	
}
